package com.jiuyuan.controller;

import com.jiuyuan.entity.Position;
import com.jiuyuan.entity.vo.RespBean;
import com.jiuyuan.service.IPositionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jiuyuan
 * @since 2023-02-15
 */
@RestController
@RequestMapping("/system/config")
public class PositionController {
    @Autowired
    IPositionService positionService;

    @GetMapping("/position")
    @ApiOperation("获取所有职位")
    public RespBean list(){
        return RespBean.success(positionService.list());
    }

    @PostMapping("/position")
    @ApiOperation("添加职位")
    public RespBean add(@RequestBody Position p){
        p.setCreateDate(LocalDateTime.now());
        if(positionService.save(p))
            return RespBean.success("添加成功");
        return RespBean.error("添加失败");
    }

    @PutMapping("/position")
    @ApiOperation("更新职位")
    public RespBean update(@RequestBody Position p){
        if(positionService.updateById(p))
            return RespBean.success("更新成功");
        return RespBean.error("更新失败");
    }

    @DeleteMapping("/position/{id}")
    @ApiOperation("删除职位")
    public RespBean delete(@PathVariable Integer id){
        if(positionService.removeById(id))
            return RespBean.success("删除成功");
        return RespBean.error("删除失败");
    }

    @DeleteMapping("/position")
    @ApiOperation("批量删除职位")
    public RespBean deleteByIds(Integer[] ids){
        if(positionService.removeBatchByIds(Arrays.asList(ids)))
            return RespBean.success("删除成功");
        return RespBean.error("删除失败");
    }

}
























